package org.agora.photogallery.client.view;

import java.util.ArrayList;

import org.agora.photogallery.client.model.Photo;



import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class PhotoCollectionViewImpl extends Composite implements PhotoCollectionView {
	private static final HorizontalPanel panel = new HorizontalPanel();
	private ArrayList<Photo> data = new ArrayList<Photo>();
	private PhotoCollectionPresenter presenter;
	
	@Inject
	public PhotoCollectionViewImpl(){
		panel.setStyleName("photoCollectionTable");
		initWidget(panel);		
	}
	@Override
	public void setData(ArrayList<Photo> photoes) {
		data = photoes;
		panel.clear();
		for(final Photo p : data){
			Image image = new Image();
			image.setUrl(p.getThumbnailUrl());
			image.setTitle(p.getCaption());
			image.addClickHandler(new ClickHandler() {				
				@Override
				public void onClick(ClickEvent event) {
					presenter.onItemClicked(p);
				}
			});	
			image.setStyleName("thumbnail");
			panel.add(image);
		}
	}

	@Override
	public Widget asWidget() {
		return this;
	}
	@Override
	public void setPresenter(PhotoCollectionPresenter p) {
		this.presenter = p;
		
	}
	
	public void hide(){
		panel.setVisible(false);
	}
	
	public void show(){
		panel.setVisible(true);
	}
	
	
}
